package com.tarena.lbs.basic.dao.repository.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tarena.lbs.basic.dao.mapper.TagTypeMapper;
import com.tarena.lbs.basic.dao.repository.TagTypeRepository;
import com.tarena.lbs.basic.pojo.po.TagTypePO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
@Slf4j
public class TagTypeRepositoryImpl implements TagTypeRepository {
    @Autowired
    private TagTypeMapper tagTypeMapper;

    @Override
    public void saveTagType(TagTypePO po) {
        // 确保主键字段为空，让数据库自动生成
        po.setId(null);//使用用自增主键
        tagTypeMapper.insert(po);
    }

    @Override
    public void updateTagType(TagTypePO po) {
        tagTypeMapper.updateById(po);
    }

    @Override
    public List<TagTypePO> tagTypeList() {
        QueryWrapper<TagTypePO> wrapper = new QueryWrapper<>();
        wrapper.eq("status", 0);
        return tagTypeMapper.selectList(wrapper);
    }

    @Override
    public TagTypePO getTagType(Integer id) {
        //根据id查出改标签的详细PO
        TagTypePO po = tagTypeMapper.selectById(id);
        //根据po找出父级标签的id,然后再查父级标签并返回
        return tagTypeMapper.selectById(po.getParentId());
    }
}
